package com.wyx.suanfa;

/**
 * 双重校验锁实现对象单例（线程安全）：
 * @author 王艺锡
 * @version 1.0
 */
public class Singleton {
    public volatile static Singleton isntance;

    public Singleton(){
    }

    public Singleton getSingleton(){
        //如果对象没有被实例过
        if(isntance == null){
            //类对象加锁
            synchronized (Singleton.class){
                //加锁后二次判断，防止上个线程刚刚创建过
                if(isntance == null){
                    isntance = new Singleton();
                }
            }
        }
        return isntance;
    }

}
